<template>
	<view>
		<view v-if="list.length === 0">
			<image class="emp-img-g" src="/static/imgs/noData.png"></image>
		</view>
		<view v-else-if="list.length !== 0">

			<view class="order-card" v-for="(i,index) in lists" :key="i.id">
				<text>预约提货时间：{{i.appoi_time | dateFormat}} </text>
				<text>提货方式：{{i.way}} </text>
				<text>应付金额：￥{{i.total}} </text>
				<view class="btn-box">
					<u-button @click="showOrdermod(index)" type="primary" size="small"
						:disabled="i.status == 0? false : true" shape="circle" :text="i.status == 0?'待取货':'已完成'">
					</u-button>
				</view>
				<u-modal :show="i.showMod" @confirm="submitCancle(index,i.id)" ref="uModal" confirmText='取消订单' cancelText='关闭'
					showCancelButton @cancel="closeOrdermod(index)" @close="closeOrdermod(index)" title='订单货物'>
					<view class="slot-content">
						<view style="padding: 15rpx;" v-for="(j,index) in i.goodsInfo" :key="index">
							{{j.good_name}} X {{j.nums}}
						</view>
					</view>
				</u-modal>
			</view>
		</view>

	</view>
</template>

<script>
	import {deleteorder} from '@/common/http.api.js'
	export default {
		props: {
			list: Array
		},
		data() {
			return {
				showMod: false,
				lists: []
			}
		},
		watch: {
			list(n, o) {
				this.lists = this.list.map((i) => {
					return {
						...i,
						showMod: false
					}
				})
			}

		},

		methods: {
			showOrdermod(index){
				this.lists[index].showMod = true
			},
			closeOrdermod(index){
				this.lists[index].showMod = false
			},
			async submitCancle(index,did) {
				uni.$loading()
				let id = did
				const res = await deleteorder({id})
				this.lists[index].showMod = false
				if(res.code === 0) uni.$showMsg('取消成功')
				this.lists = this.lists.filter(i=> i.id !== did)
			},

		}
	}
</script>

<style lang="scss" scoped>
	.order-card {
		box-shadow: 0rpx 2rpx 7rpx 0 rgba(0, 0, 0, 0.08);
		border-radius: 15rpx;
		margin: 25rpx auto;
		padding: 15rpx;
		width: 90%;
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		font-size: 13px;
		position: relative;

		text {
			display: block;
			padding: 0 15rpx;
		}

		.btn-box {
			position: absolute;
			top: 50%;
			right: -20rpx;
			transform: translate(-50%, -50%);
		}
	}
</style>
